<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="Bookmark" href="/favicon.ico">
		<link rel="Shortcut Icon" href="/favicon.ico" />
		<link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
		<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
		<link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
		<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
		<link rel="stylesheet" href="../lib/layui/css/layui.css">

		<title>角色管理</title>
	</head>

	<body>
		<!--修改参数-->
		<input type="hidden" id="update_id" />
		<input type="hidden" id="role_id" />

		<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 后台管理 <span class="c-gray en">&gt;</span> 角色管理
			<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
		</nav>
		<div class="page-container">
			<div class="layui-inline">
				<input class="input-text" placeholder="清输入角色名称" id="name" autocomplete="off">
			</div>
			<button class="layui-btn layui-btn-sm" onclick="tableReload();">搜索</button>
			<script type="text/html" id="tableTool">
				<div class="layui-btn-container">
					<div class="layui-btn-group">
						<button class="layui-btn layui-btn-sm" lay-event="t_add"><i class="layui-icon">&#xe654;</i></button>
					</div>
				</div>
			</script>
			<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
			<script type="text/html" id="barOperation">
				<a title="修改" lay-event="update" class="layui-btn layui-btn-danger layui-btn-xs">修改</a>
				<a title="删除" lay-event="delete" class="layui-btn layui-btn-danger layui-btn-xs">删除</a>
				<a title="配置资源" lay-event="setSources" class="layui-btn layui-btn-danger layui-btn-xs">配置资源</a>
				<a title="授权管理员" lay-event="authSysUser" class="layui-btn layui-btn-danger layui-btn-xs">授权管理员</a>
			</script>
		</div>
		<div id="pager" class="clearfix"></div>
		<!--_footer 作为公共模版分离出去-->
		<script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
		<script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
		<script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
		<script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
		<!--/_footer 作为公共模版分离出去-->
		<script type="text/javascript" src="../lib/layui/layui.js"></script>
		<script type="text/javascript" src="../static/js/common.js"></script>
		<!--请在下方写此页面业务相关的脚本-->
		<script type="text/javascript">
			var dataTable;
			layui.use('table', function() {
				var table = layui.table;
				dataTable = table.render({
					elem: '#tableList',
					id: 'reload',
					method: 'POST',
					url: admin_url + '/scaRole/roleList',
					toolbar: '#tableTool',
					page: true,
					request: {
						pageName: 'page',
						limitName: 'size'
					},
					response: {
						statusName: 'code',
						statusCode: 200,
						msgName: 'msg',
						countName: 'count',
						dataName: 'data'
					},
					where: {
						"token": token,
						"tokenUserId": userId,
					},
					cols: [
						[{
								checkbox: true,
								align: 'center',
							},
							{
								field: 'id',
								title: 'ID',
								align: 'center',
								width: 80
							},
							{
								field: 'name',
								title: '角色名',
								align: 'center',
							},
							{
								field: 'status',
								title: '状态',
								align: 'center',
								width: 80,
								templet: function(e) {
									if(e.status == 0) {
										return '<span class="layui-badge">禁用</span>'
									} else if(e.status == 1) {
										return '<span class="layui-badge layui-bg-green">正常</span>'
									} else {
										return "";
									}
								}
							},
							{
								field: 'sort',
								title: '排序',
								align: 'center'
							},
							{
								field: 'description',
								title: '描述',
								align: 'center'
							},
							{
								field: 'createTime',
								title: '创建时间',
								align: 'center'
							},
							{
								toolbar: '#barOperation',
								title: '操作',
								align: 'center'
							}
						]
					]
				});

				//监听工具条
				table.on('tool(tableList)', function(obj) {
					var data = obj.data;
					if(obj.event === 'delete') {
						t_delete(data.id);
					} else if(obj.event === 'update') {
						t_update(data.id);
					} else if(obj.event === 'setSources') {
						setSources(data.id);
					} else if(obj.event === 'authSysUser') {
						authSysUser(data.id);
					}
				});

				table.on('toolbar(tableList)', function(obj) {
					var data = obj.data;
					if(obj.event === 't_add') {
						t_add();
					}
				});

			})

			function tableReload() {
				//执行重载
				dataTable.reload({
					where: {
						"token": token,
						"tokenUserId": userId,
						"name": $("#name").val(),
					}
				});
			}

			function t_add() {
				layer.open({
					title: "新增角色",
					type: 2,
					area: ['90%', '90%'],
					content: '../root/sys_role_add.html'
				});
				$("#update_id").val("");
			}

			function t_update(id) {
				layer.open({
					title: "修改管理员信息",
					type: 2,
					area: ['90%', '90%'],
					content: '../root/sys_role_add.html'
				});
				$("#update_id").val(id);
			}

			function t_delete(id) {
				myConfirm("<span style='text-align:center'>确认删除当前角色吗？</span>", function() {
					var data = {
						"token": token,
						"tokenUserId": userId,
						"id": id
					};
					request_ajax("POST", admin_url + '/scaRole/delRole', data, function(res) {
						layer.msg(res.msg, {
							time: 800
						});
						tableReload();
					});
				});
			}

			//设置角色对应资源
			function setSources(roleId) {
				layer.open({
					title: "配置资源",
					type: 2,
					area: ['90%', '90%'],
					content: '../root/auth_sources.html'
				});
				$("#role_id").val(roleId);

			}
			//设置角色对应系统管理员
			function authSysUser(roleId) {
				layer.open({
					title: "授权管理员",
					type: 2,
					area: ['90%', '90%'],
					content: '../root/auth_users.html'
				});
				$("#role_id").val(roleId);
			}
		</script>
	</body>

</html>